package db

import (
	"go-study/src/sjcc/models"
	"gorm.io/gorm"
	"log"
)

// 创建  手动关闭连接
func InsertMajor(db *gorm.DB, major models.Major) {
	connection, err := db.DB()
	if err != nil {
		log.Fatalf("failed to connect database: %v", err)
	}
	db.Create(&major)
	closeErr := connection.Close()
	if err != nil {
		log.Println("close collection is error" + closeErr.Error())
	}
}

// 查询
func QueryMajor(db *gorm.DB) {
	// 读取
	var majors []models.Major
	db.Find(&majors)
}

// 更新
func UpdateMajor(db *gorm.DB, major models.Major) {
	// 更新
	db.Model(&major).Updates(models.Major{})
}

// 删除
func DeleteMajor(db *gorm.DB, major models.Major) {
	// 删除
	db.Delete(&models.Major{}, 1)
}

//func main() {
//	db := GetGormDB()
//	fmt.Println(db)
//}
